package pl.edu.pw.perg.compinfodb.manager;

import java.util.List;
import java.util.Set;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pl.edu.pw.perg.compinfodb.dao.IConnectorDAO;
import pl.edu.pw.perg.compinfodb.entities.Connector;
import pl.edu.pw.perg.compinfodb.entities.VirtualElement;

public class ConnectorManager extends GenericManager<Connector> 
implements IConnectorManager {

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public List<Connector> findInputConnectors(VirtualElement virtualElement) {
		return ((IConnectorDAO) getGenericDAO()).findInputConnectors(virtualElement);
	}

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public List<Connector> findOutputConnectors(VirtualElement virtualElement) {
		return ((IConnectorDAO) getGenericDAO()).findOutputConnectors(virtualElement);
	}

//  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
//  public Map<Connector, Connector> getConnectorsMap(Collection<Connector> connectors){
//    Map<Connector, Connector> connMap = new HashMap<Connector, Connector>();
//    for (Connector connector : connectors) {
//      Long id = connector.getExternalConnectorId();
//      if(id!=null)
//        connMap.put(connector, findById(id));
//    }
//    return connMap;
//  }
//  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
//  public Connector getNext(Connector conn){
//    return findById(conn.getExternalConnectorId());
//  }
//  
//  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
//  public List<VirtualElement> getConnectorsPath(Connector connector){
//    List<VirtualElement> elts = new ArrayList<VirtualElement>();
//    Long id = connector.getExternalConnectorId();
//    Connector cableConnector = null;
//    if(id==null)
//      return elts;
//       cableConnector = findById(id);
//    Cable cable = (Cable) cableConnector.getElement();
//    Long nextCableConn = cableConnector.getInput()? cable.getOutput().getExternalConnectorId() :
//      cable.getInput().getExternalConnectorId();
//    VirtualElement elt = findById(nextCableConn).getElement();    
//    elts.add(cable);
//    elts.add(elt);
//    return elts;
//  }
}
